package cn.felord.security.autoconfigure.authentication.miniapp.douyin;

import cn.felord.security.autoconfigure.authentication.miniapp.AbstractMiniAppSessionAuthenticationFilter;
import cn.felord.security.autoconfigure.authentication.miniapp.MiniAppSessionRequest;
import cn.felord.security.autoconfigure.authentication.miniapp.MiniAppSessionService;
import cn.felord.security.autoconfigure.authentication.miniapp.MiniClientType;
import cn.felord.security.autoconfigure.LoginAntPathPatterns;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;

import java.io.IOException;

/**
 * DouyinMiniAppSessionAuthenticationFilter
 *
 * @author felord.cn
 * @since 2021 /9/1 8:51
 */
public class DouyinMiniAppSessionAuthenticationFilter extends AbstractMiniAppSessionAuthenticationFilter {
    /**
     * Instantiates a new Douyin mini app session authentication filter.
     *
     * @param miniAppSessionService the mini app session service
     */
    public DouyinMiniAppSessionAuthenticationFilter(MiniAppSessionService miniAppSessionService) {
        super(miniAppSessionService,new AntPathRequestMatcher(LoginAntPathPatterns.DOUYIN_MINIAPP_SESSION.pattern(),"POST"));
    }

    /**
     * Instantiates a new Abstract mini app session authentication filter.
     *
     * @param miniAppSessionService miniAppSessionService
     * @param requestMatcher        requestMatcher
     */
    public DouyinMiniAppSessionAuthenticationFilter(MiniAppSessionService miniAppSessionService, RequestMatcher requestMatcher) {
        super(miniAppSessionService, requestMatcher);
    }

    @Override
    protected MiniAppSessionRequest enhance(MiniAppSessionRequest appSessionRequest) {
        appSessionRequest.setClientType(MiniClientType.DOUYIN);
        return appSessionRequest;
    }
}
